package com.miracle.pagestatedemo

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.miracle.pagestatedemo.databinding.FragmentMyBinding

class MyFragment : Fragment() {

    private lateinit var mContext: Context
    private lateinit var mBinding: FragmentMyBinding

    override fun onAttach(context: Context) {
        super.onAttach(context)
        mContext = context
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        mBinding = FragmentMyBinding.inflate(layoutInflater, container, false)
        return mBinding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initListener()
    }


    private fun initListener() {
        mBinding.tvNormal2.setOnClickListener {
            mBinding.pageStateView.showContentView()
        }
        mBinding.tvLoading2.setOnClickListener {
            mBinding.pageStateView.showLoadingView()
        }
        mBinding.tvEmpty2.setOnClickListener {
            mBinding.pageStateView.showEmptyView()
        }
        mBinding.tvNetError2.setOnClickListener {
            mBinding.pageStateView.showNetErrorView()
        }
        mBinding.tvServerError2.setOnClickListener {
            mBinding.pageStateView.showServerErrorView()
        }
    }

}